<template>
  <div class="bg">
    <el-card class="box">
      <h2 align="center">注册</h2>
      <el-form ref="formRef" label-width="80px" :model="form" :rules="formRules">
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="验证码" prop="code">
          <el-input v-model="form.code" placeholder="请输入验证码" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="handleLogin">登录</el-button>
          <el-button type="info" plain @click="handleReset">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { validatorAge } from '@/utils/validate.js'
export default {
  name: 'Playground',
  data() {
    return {
      form: {
        mobile: '',
        code: '',
        age: ''
      },
      formRules: {
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { pattern: /^1[3-9]\d{9}$/, meaasge: '请输入正确的手机号', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '请输入验证码', trigger: 'blur' },
          {
            pattern: /^\d{6}$/,
            message: '请输入正确的验证码',
            trigger: ['blur', 'change']
          }
        ],
        age: [
          { required: true, message: '请输入年龄', trigger: 'blur' },
          { validator: validatorAge, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    handleLogin() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          //
        } else {
          this.$message.error('校验失败! ')
        }
      })
    },
    handleReset() {
      this.$refs.formRef.resetFields()
    }
  }

}
</script>

<style lang="scss" scoped>

.bg{
  width: 100%;
  height: 100%;
  // background:linear-gradient(0deg,#7700FF ,#B088FF,#D1BBFF);
  background:linear-gradient(0deg,#a8edea ,#fed6e3);
  // background:linear-gradient(0deg,#5ee7df ,#b490ca);
  // background-color: rgba(#a9a9a9,  0.3);
  overflow: hidden;
  .box{
    width: 500px;
    margin: 100px auto;
    background-color: rgba(#fff,  0.3);
    border-radius: 10px;
    // box-shadow: 5px 5px 5px #a9a9a9,-5px -5px 5px #a9a9a9;
    padding: 10px 15px 10px 0px;
  }
}

</style>
